package edu.zut.hb.bailan0.producter;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;
public class ConnectionUtils {
    private static final String IP_ADDRESS = "192.168.234.46";
    private static final int PORT = 5672;//RabbitMQ 服务端默认端口号为5672
    /**
     *   获取mq的链接  定义一个链接工厂
     * @return
     * @throws IOException
     * @throws TimeoutException
     */
    public static Connection  getConnection() throws IOException, TimeoutException{
        //定义一个连接工厂
        ConnectionFactory factory =new ConnectionFactory();
        //设置服务地址
        factory.setHost(IP_ADDRESS);
        //AMQP 5672
        factory.setPort(PORT);
        //用户名
        factory.setUsername("wang");
        //密码
        factory.setPassword("123456");

        return factory.newConnection();
    }

}
